# -*- coding:utf-8 -*-#
"""
作者：王凯
日期：2024年09月24日
时间：13时23分
"""

# https://www.bizhi99.com/s/112692/
# 迪丽热巴图片链接打印
import requests
import re

url = "https://www.bizhi99.com/s/112692/"
headers = {#请求头
    "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.88 Safari/537.36"
}
response = requests.get(url, headers=headers)  #发送请求
response.encoding = "utf-8"  #编码格式

content = response.text  #获取网页内容
f = open("迪丽热巴.html", "w", encoding="utf-8")
f.write(content)
f.close()

"""
 <img class="lazy" src="https://pic.dmjnb.com/pic/f403596831196f32e33d3f6d2ee92c10?imageMogr2/thumbnail/x380/quality/90!" 
        data-original="https://pic.dmjnb.com/pic/f403596831196f32e33d3f6d2ee92c10?imageMogr2/thumbnail/x380/quality/90!" 
 alt="蝴蝶仙子 迪丽热巴4k美女壁纸 4k手机壁纸" style="display: block;">
"""
# 正则表达式提取图片链接
"""
pattern = re.compile(r'<img.*?data-original="(.*?!)"', re.S)      # 匹配图片链接
result = re.findall(pattern, content)      # 结果列表
# https://pic.dmjnb.com/pic/f403596831196f32e33d3f6d2ee92c10?imageMogr2/thumbnail/x380/quality/90!
for i in result:
    print(i)
    """
#     f = open("迪丽热巴.jpg", "wb")
#     f.write(requests.get(i).content)
#     f.close()
# print(re.findall(pattern, content))
# re: 匹配第一个图片链接
# findall: 匹配所有图片链接
# pattern: 正则表达式
# content: 网页内容